/*************************************************************************
 RUN_REGRESSIONS.SAS
    Code to run regressions.

    This program uses several external files with code to make tables
    of results.
    
*************************************************************************/
*OPTIONS MPRINT MLOGIC;
   
* Define the local directory in which you are working;
%LET LOCAL = /mnt/Research/RESTAT;
LIBNAME HERE "&LOCAL";

%INCLUDE 'makegenmodtable.code';

/* ------------------------------------------------------------------------------
 Macro to run regression specifications
 IPVAR is the IP measure to use
 NEGVAR is the neglected disease measure to use
 DEPENDENTVAR is the dependent variable (which phase) to use
 SET specifies which market size measure to use:
    1 is total,
    2 is disease type (global or neglected),
    3 is disease type*IP,
    4 is disease*income level*IP
 COLNUM specifies the column number for the call to the table-making macro
------------------------------------------------------------------------------*/
%MACRO DISEASE_START_REGS(IPVAR,NEGVAR,DEPENDENTVAR,SET,COLNUM);

   PROC SORT DATA=HERE.REGRESSION_DATA&USEDATA;
    BY _IMPUTATION_;

   DATA TEST;
     SET HERE.REGRESSION_DATA&USEDATA;

   * This assigns diseases with many new projects a maximum value of 75;
     &DEPENDENTVAR = MIN(&DEPENDENTVAR,75);

   * Interact market size with IP and neglected variables;
     DEATHS_IP_G_4 = DEATHS_&IPVAR._4*(&NEGVAR EQ 0);
     DEATHS_IP_N_4 = DEATHS_&IPVAR._4*(&NEGVAR EQ 1);
     DEATHS_NO_G_4 = DEATHS_NO&IPVAR._4*(&NEGVAR EQ 0);
     DEATHS_NO_N_4 = DEATHS_NO&IPVAR._4*(&NEGVAR EQ 1);
     DEATHS_IP_G_3 = DEATHS_&IPVAR._3*(&NEGVAR EQ 0);
     DEATHS_IP_N_3 = DEATHS_&IPVAR._3*(&NEGVAR EQ 1);
     DEATHS_NO_G_3 = DEATHS_NO&IPVAR._3*(&NEGVAR EQ 0);
     DEATHS_NO_N_3 = DEATHS_NO&IPVAR._3*(&NEGVAR EQ 1);
     DEATHS_IP_G_2 = DEATHS_&IPVAR._2*(&NEGVAR EQ 0);
     DEATHS_IP_N_2 = DEATHS_&IPVAR._2*(&NEGVAR EQ 1);
     DEATHS_NO_G_2 = DEATHS_NO&IPVAR._2*(&NEGVAR EQ 0);
     DEATHS_NO_N_2 = DEATHS_NO&IPVAR._2*(&NEGVAR EQ 1);
     DEATHS_IP_G_1 = DEATHS_&IPVAR._1*(&NEGVAR EQ 0);
     DEATHS_IP_N_1 = DEATHS_&IPVAR._1*(&NEGVAR EQ 1);
     DEATHS_NO_G_1 = DEATHS_NO&IPVAR._1*(&NEGVAR EQ 0);
     DEATHS_NO_N_1 = DEATHS_NO&IPVAR._1*(&NEGVAR EQ 1);

   * Create aggregate market size measures. Since deaths are logged
     values, need to exponentiate first.;        
     TOTAL_DEATHS = SUM(DEATHS_IP_G_4,
			DEATHS_IP_N_4,
			DEATHS_NO_G_4,
			DEATHS_NO_N_4,
			DEATHS_IP_G_3,
			DEATHS_IP_N_3,
			DEATHS_NO_G_3,
			DEATHS_NO_N_3,
			DEATHS_IP_G_2,
			DEATHS_IP_N_2,
			DEATHS_NO_G_2,
			DEATHS_NO_N_2,
			DEATHS_IP_G_1,
			DEATHS_IP_N_1,
			DEATHS_NO_G_1,
			DEATHS_NO_N_1);

     TOTAL_GLOBAL = SUM(DEATHS_IP_G_4,
			DEATHS_NO_G_4,
			DEATHS_IP_G_3,
			DEATHS_NO_G_3,
			DEATHS_IP_G_2,
			DEATHS_NO_G_2,
			DEATHS_IP_G_1,
			DEATHS_NO_G_1);

     TOTAL_NEGLECTED = SUM(DEATHS_IP_N_4,
			DEATHS_NO_N_4,
			DEATHS_IP_N_3,
			DEATHS_NO_N_3,
			DEATHS_IP_N_2,
			DEATHS_NO_N_2,
			DEATHS_IP_N_1,
			DEATHS_NO_N_1);

     TOTAL_IP_G =   SUM(DEATHS_IP_G_4,
			DEATHS_IP_G_3,
			DEATHS_IP_G_2,
			DEATHS_IP_G_1);

     TOTAL_IP_N =   SUM(DEATHS_IP_N_4,
			DEATHS_IP_N_3,
			DEATHS_IP_N_2,
			DEATHS_IP_N_1);

     TOTAL_NO_G =   SUM(DEATHS_NO_G_4,
			DEATHS_NO_G_3,
			DEATHS_NO_G_2,
			DEATHS_NO_G_1);

     TOTAL_NO_N =   SUM(DEATHS_NO_N_4,
			DEATHS_NO_N_3,
			DEATHS_NO_N_2,
			DEATHS_NO_N_1);

     YEAR1990 = (YEAR EQ 1990);
     YEAR1991 = (YEAR EQ 1991);
     YEAR1992 = (YEAR EQ 1992);
     YEAR1993 = (YEAR EQ 1993);
     YEAR1994 = (YEAR EQ 1994);
     YEAR1995 = (YEAR EQ 1995);
     YEAR1996 = (YEAR EQ 1996);
     YEAR1997 = (YEAR EQ 1997);
     YEAR1998 = (YEAR EQ 1998);
     YEAR1999 = (YEAR EQ 1999);
     YEAR2000 = (YEAR EQ 2000);
     YEAR2001 = (YEAR EQ 2001);
     YEAR2002 = (YEAR EQ 2002);
     YEAR2003 = (YEAR EQ 2003);
     YEAR2004 = (YEAR EQ 2004);
     YEAR2005 = (YEAR EQ 2005);
     YEAR2006 = (YEAR EQ 2006);

  %IF &SET EQ 4 %THEN 
  %LET VARLIST = TREATMENTS1990
		 DEATHS_IP_G_4
		 DEATHS_IP_N_4
		 DEATHS_NO_G_4
		 DEATHS_NO_N_4
		 DEATHS_IP_G_3
		 DEATHS_IP_N_3
		 DEATHS_NO_G_3
		 DEATHS_NO_N_3
		 DEATHS_IP_G_2
		 DEATHS_IP_N_2
		 DEATHS_NO_G_2
		 DEATHS_NO_N_2
		 DEATHS_IP_G_1
		 DEATHS_IP_N_1
		 DEATHS_NO_G_1
		 DEATHS_NO_N_1
		 YEAR1991
		 YEAR1992
		 YEAR1993
		 YEAR1994
		 YEAR1995
		 YEAR1996
		 YEAR1997
		 YEAR1998
		 YEAR1999
		 YEAR2000
		 YEAR2001
		 YEAR2002
		 YEAR2003
		 YEAR2004
		 YEAR2005
		 YEAR2006;

  %IF &SET EQ 1 %THEN 
  %LET VARLIST = TREATMENTS1990
		 TOTAL_DEATHS
	         YEAR1991
		 YEAR1992
		 YEAR1993
		 YEAR1994
		 YEAR1995
		 YEAR1996
		 YEAR1997
		 YEAR1998
		 YEAR1999
		 YEAR2000
		 YEAR2001
		 YEAR2002
		 YEAR2003
		 YEAR2004
		 YEAR2005
		 YEAR2006;

  %IF &SET EQ 2 %THEN 
  %LET VARLIST = TREATMENTS1990 TOTAL_GLOBAL TOTAL_NEGLECTED
		 YEAR1991
		 YEAR1992
		 YEAR1993
		 YEAR1994
		 YEAR1995
		 YEAR1996
		 YEAR1997
		 YEAR1998
		 YEAR1999
		 YEAR2000
		 YEAR2001
		 YEAR2002
		 YEAR2003
		 YEAR2004
		 YEAR2005
		 YEAR2006;

  %IF &SET EQ 3 %THEN 
  %LET VARLIST = TREATMENTS1990
		 TOTAL_IP_G TOTAL_IP_N
		 TOTAL_NO_G TOTAL_NO_N	         
		 YEAR1991
		 YEAR1992
		 YEAR1993
		 YEAR1994
		 YEAR1995
		 YEAR1996
		 YEAR1997
		 YEAR1998
		 YEAR1999
		 YEAR2000
		 YEAR2001
		 YEAR2002
		 YEAR2003
		 YEAR2004
		 YEAR2005
		 YEAR2006;

   PROC FREQ DATA=TEST;
	TABLES &DEPENDENTVAR;
   PROC MEANS DATA=TEST;

   PROC GENMOD DATA=TEST  (WHERE=(_IMPUTATION_ NE .)) NAMELEN=50;
    CLASS WHO_CODE / DESCENDING;
    MODEL &DEPENDENTVAR =  &VARLIST / DIST=NB COVB OBSTATS;
    OUTPUT OUT=OUTME XBETA=XB;
    REPEATED SUBJECT = WHO_CODE;
    BY _IMPUTATION_;
    ODS OUTPUT GEEEMPPEST=EST&COLNUM 
	     GEEFITCRITERIA=FIT&COLNUM
	     NOBS=NUMBEROBS&COLNUM
	     MODELINFO=INFO&COLNUM
	     PARMINFO=GMPINFO&COLNUM
	     COVB=GMCOVB&COLNUM;

    PROC MIANALYZE PARMS=EST&COLNUM COVB=GMCOVB&COLNUM PARMINFO=GMPINFO&COLNUM;
	MODELEFFECTS INTERCEPT &VARLIST;
    %IF &SET EQ 2 %THEN %DO;
	TEST_GN: TEST TOTAL_GLOBAL = TOTAL_NEGLECTED;
    ODS OUTPUT PARAMETERESTIMATES=MI_EST&COLNUM 
	     MODELINFO=MI_INFO&COLNUM
	     TESTPARAMETERESTIMATES=MI_TESTPARM&COLNUM;
    %END;
    %ELSE %IF &SET EQ 3 %THEN %DO;
	TEST_IP_N: TEST TOTAL_IP_N = TOTAL_NO_N;
	TEST_IP_G: TEST TOTAL_IP_G = TOTAL_NO_G;
	TEST_GN_IP: TEST TOTAL_IP_G = TOTAL_IP_N;
	TEST_GN_NO: TEST TOTAL_NO_G = TOTAL_NO_N;
    ODS OUTPUT PARAMETERESTIMATES=MI_EST&COLNUM 
	     MODELINFO=MI_INFO&COLNUM
	     TESTPARAMETERESTIMATES=MI_TESTPARM&COLNUM;
    %END;
    %ELSE %IF &SET EQ 4 %THEN %DO;
	TEST_IP_N_4: TEST DEATHS_IP_N_4 = DEATHS_NO_N_4;
	TEST_IP_G_4: TEST DEATHS_IP_G_4 = DEATHS_NO_G_4;
	TEST_GN_IP_4: TEST DEATHS_IP_G_4 = DEATHS_IP_N_4;
	TEST_GN_NO_4: TEST DEATHS_NO_G_4 = DEATHS_NO_N_4;
	TEST_IP_N_3: TEST DEATHS_IP_N_3 = DEATHS_NO_N_3;
	TEST_IP_G_3: TEST DEATHS_IP_G_3 = DEATHS_NO_G_3;
	TEST_GN_IP_3: TEST DEATHS_IP_G_3 = DEATHS_IP_N_3;
	TEST_GN_NO_3: TEST DEATHS_NO_G_3 = DEATHS_NO_N_3;
	TEST_IP_N_2: TEST DEATHS_IP_N_2 = DEATHS_NO_N_2;
	TEST_IP_G_2: TEST DEATHS_IP_G_2 = DEATHS_NO_G_2;
	TEST_GN_IP_2: TEST DEATHS_IP_G_2 = DEATHS_IP_N_2;
	TEST_GN_NO_2: TEST DEATHS_NO_G_2 = DEATHS_NO_N_2;
	TEST_IP_N_1: TEST DEATHS_IP_N_1 = DEATHS_NO_N_1;
	TEST_IP_G_1: TEST DEATHS_IP_G_1 = DEATHS_NO_G_1;
	TEST_GN_IP_1: TEST DEATHS_IP_G_1 = DEATHS_IP_N_1;
	TEST_GN_NO_1: TEST DEATHS_NO_G_1 = DEATHS_NO_N_1;
    ODS OUTPUT PARAMETERESTIMATES=MI_EST&COLNUM 
	     MODELINFO=MI_INFO&COLNUM
	     TESTPARAMETERESTIMATES=MI_TESTPARM&COLNUM;
    %END;
    %ELSE %DO;
    ODS OUTPUT PARAMETERESTIMATES=MI_EST&COLNUM 
	     MODELINFO=MI_INFO&COLNUM;
    %END;

    PROC MEANS DATA=OUTME NOPRINT;
    VAR XB;
    OUTPUT OUT=AVG_XB MEAN(XB) = XB;

    DATA AVG_XB;
       SET AVG_XB (KEEP=XB);
       MERGEVAL = 1;
    PROC SORT;
       BY MERGEVAL;

    DATA MI_EST&COLNUM;
       SET MI_EST&COLNUM;
       MERGEVAL = 1;
    PROC SORT;
       BY MERGEVAL;

    DATA MI_EST&COLNUM (DROP=MERGEVAL);
      MERGE MI_EST&COLNUM AVG_XB;
      BY MERGEVAL;
      MEM = ESTIMATE*EXP(XB);
    PROC PRINT;

%MEND(DISEASE_START_REGS);

* USEDATA specifies whether the dataset to use has lagged values of market size;
%LET USEDATA = ;
* PREFIX species the prefix used in file names containing the results;
%LET PREFIX = TRIPS_results&USEDATA;

* ------------------------------------------------------------------------------;
* Baseline results: no lag, Phase 1, neglected definition includes HIV, TRIPS measure;
* ------------------------------------------------------------------------------;
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,1,1);
    FILENAME RESULTS "&PREFIX._SET1_A.txt";
    %MAKEGENMODTABLE("Baseline results: all P1 starts, HIV as neglected, TRIPS measure",1);
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,2,1);
    FILENAME RESULTS "&PREFIX._SET1_B.txt";
    %MAKEGENMODTABLE("Baseline results: all P1 starts, HIV as neglected, TRIPS measure",1);
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,3,1);
    FILENAME RESULTS "&PREFIX._SET1_C.txt";
    %MAKEGENMODTABLE("Baseline results: all P1 starts, HIV as neglected, TRIPS measure",1);
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,4,1);
    FILENAME RESULTS "&PREFIX._SET1_D.txt";
    %MAKEGENMODTABLE("Baseline results: all P1 starts, HIV as neglected, TRIPS measure",1,4);


* ------------------------------------------------------------------------------;
* Robustness check: lagged market size, Phase 1, neglected definition includes HIV, TRIPS measure;
* ------------------------------------------------------------------------------;
%LET USEDATA = _LAG;
%LET PREFIX = TRIPS_results&USEDATA;
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,1,1);
    FILENAME RESULTS "&PREFIX._SET2_A.txt";
    %MAKEGENMODTABLE("Robustness check: all P1 starts, HIV as neglected, TRIPS measure, lagged market size",1);
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,2,1);
    FILENAME RESULTS "&PREFIX._SET2_B.txt";
    %MAKEGENMODTABLE("Robustness check: all P1 starts, HIV as neglected, TRIPS measure, lagged market size",1);
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,3,1);
    FILENAME RESULTS "&PREFIX._SET2_C.txt";
    %MAKEGENMODTABLE("Robustness check: all P1 starts, HIV as neglected, TRIPS measure, lagged market size",1);
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,4,1);
    FILENAME RESULTS "&PREFIX._SET2_D.txt";
    %MAKEGENMODTABLE("Robustness check: all P1 starts, HIV as neglected, TRIPS measure, lagged market size",1,4);

* ------------------------------------------------------------------------------;
* Robustness check: no lag, Phase 1, neglected definition includes HIV,
  different IP measures;
* ------------------------------------------------------------------------------;
%LET USEDATA = ;
%LET PREFIX = TRIPS_results&USEDATA;
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,4,1);
%DISEASE_START_REGS(GP,NEGLECTED,NEW_PHASE1,4,2);
%DISEASE_START_REGS(H,NEGLECTED,NEW_PHASE1,4,3);
%DISEASE_START_REGS(IPMIN,NEGLECTED,NEW_PHASE1,4,4);
%DISEASE_START_REGS(IPMAX,NEGLECTED,NEW_PHASE1,4,5);
FILENAME RESULTS "&PREFIX._SET3.txt";
%MAKEGENMODTABLE("Robustness check 2: all P1 starts, HIV as neglected, different IP measures",5,4);


* ------------------------------------------------------------------------------;
* Robustness check: no lag, Phase 1, neglected definition varies, TRIPS measure;
* ------------------------------------------------------------------------------;
%DISEASE_START_REGS(TRIPS,NEGLECTED,NEW_PHASE1,4,1);
%DISEASE_START_REGS(TRIPS,NEGLECTED_NONHIV,NEW_PHASE1,4,2);
* This last specification excludes HIV from the analysis.;    
   DATA TEST;
     SET HERE.REGRESSION_DATA (WHERE=(WHO_CODE NE '1020'));

     NEW_PHASE1 = MIN(NEW_PHASE1,75);

     DEATHS_IP_G_4 = DEATHS_TRIPS_4*(NEGLECTED EQ 0);
     DEATHS_IP_N_4 = DEATHS_TRIPS_4*(NEGLECTED EQ 1);
     DEATHS_NO_G_4 = DEATHS_NOTRIPS_4*(NEGLECTED EQ 0);
     DEATHS_NO_N_4 = DEATHS_NOTRIPS_4*(NEGLECTED EQ 1);
     DEATHS_IP_G_3 = DEATHS_TRIPS_3*(NEGLECTED EQ 0);
     DEATHS_IP_N_3 = DEATHS_TRIPS_3*(NEGLECTED EQ 1);
     DEATHS_NO_G_3 = DEATHS_NOTRIPS_3*(NEGLECTED EQ 0);
     DEATHS_NO_N_3 = DEATHS_NOTRIPS_3*(NEGLECTED EQ 1);
     DEATHS_IP_G_2 = DEATHS_TRIPS_2*(NEGLECTED EQ 0);
     DEATHS_IP_N_2 = DEATHS_TRIPS_2*(NEGLECTED EQ 1);
     DEATHS_NO_G_2 = DEATHS_NOTRIPS_2*(NEGLECTED EQ 0);
     DEATHS_NO_N_2 = DEATHS_NOTRIPS_2*(NEGLECTED EQ 1);
     DEATHS_IP_G_1 = DEATHS_TRIPS_1*(NEGLECTED EQ 0);
     DEATHS_IP_N_1 = DEATHS_TRIPS_1*(NEGLECTED EQ 1);
     DEATHS_NO_G_1 = DEATHS_NOTRIPS_1*(NEGLECTED EQ 0);
     DEATHS_NO_N_1 = DEATHS_NOTRIPS_1*(NEGLECTED EQ 1);

     TOTAL_DEATHS = SUM(DEATHS_IP_G_4,
			DEATHS_IP_N_4,
			DEATHS_NO_G_4,
			DEATHS_NO_N_4,
			DEATHS_IP_G_3,
			DEATHS_IP_N_3,
			DEATHS_NO_G_3,
			DEATHS_NO_N_3,
			DEATHS_IP_G_2,
			DEATHS_IP_N_2,
			DEATHS_NO_G_2,
			DEATHS_NO_N_2,
			DEATHS_IP_G_1,
			DEATHS_IP_N_1,
			DEATHS_NO_G_1,
			DEATHS_NO_N_1);

     TOTAL_GLOBAL = SUM(DEATHS_IP_G_4,
			DEATHS_NO_G_4,
			DEATHS_IP_G_3,
			DEATHS_NO_G_3,
			DEATHS_IP_G_2,
			DEATHS_NO_G_2,
			DEATHS_IP_G_1,
			DEATHS_NO_G_1);

     TOTAL_NEGLECTED = SUM(DEATHS_IP_N_4,
			DEATHS_NO_N_4,
			DEATHS_IP_N_3,
			DEATHS_NO_N_3,
			DEATHS_IP_N_2,
			DEATHS_NO_N_2,
			DEATHS_IP_N_1,
			DEATHS_NO_N_1);

     TOTAL_IP_G =   SUM(DEATHS_IP_G_4,
			DEATHS_IP_G_3,
			DEATHS_IP_G_2,
			DEATHS_IP_G_1);

     TOTAL_IP_N =   SUM(DEATHS_IP_N_4,
			DEATHS_IP_N_3,
			DEATHS_IP_N_2,
			DEATHS_IP_N_1);

     TOTAL_NO_G =   SUM(DEATHS_NO_G_4,
			DEATHS_NO_G_3,
			DEATHS_NO_G_2,
			DEATHS_NO_G_1);

     TOTAL_NO_N =   SUM(DEATHS_NO_N_4,
			DEATHS_NO_N_3,
			DEATHS_NO_N_2,
			DEATHS_NO_N_1);

     YEAR1990 = (YEAR EQ 1990);
     YEAR1991 = (YEAR EQ 1991);
     YEAR1992 = (YEAR EQ 1992);
     YEAR1993 = (YEAR EQ 1993);
     YEAR1994 = (YEAR EQ 1994);
     YEAR1995 = (YEAR EQ 1995);
     YEAR1996 = (YEAR EQ 1996);
     YEAR1997 = (YEAR EQ 1997);
     YEAR1998 = (YEAR EQ 1998);
     YEAR1999 = (YEAR EQ 1999);
     YEAR2000 = (YEAR EQ 2000);
     YEAR2001 = (YEAR EQ 2001);
     YEAR2002 = (YEAR EQ 2002);
     YEAR2003 = (YEAR EQ 2003);
     YEAR2004 = (YEAR EQ 2004);
     YEAR2005 = (YEAR EQ 2005);
     YEAR2006 = (YEAR EQ 2006);

  %LET VARLIST = DEATHS_IP_G_4
		 DEATHS_IP_N_4
		 DEATHS_NO_G_4
		 DEATHS_NO_N_4
		 DEATHS_IP_G_3
		 DEATHS_IP_N_3
		 DEATHS_NO_G_3
		 DEATHS_NO_N_3
		 DEATHS_IP_G_2
		 DEATHS_IP_N_2
		 DEATHS_NO_G_2
		 DEATHS_NO_N_2
		 DEATHS_IP_G_1
		 DEATHS_IP_N_1
		 DEATHS_NO_G_1
		 DEATHS_NO_N_1
	         TREATMENTS1990
		 YEAR1991
		 YEAR1992
		 YEAR1993
		 YEAR1994
		 YEAR1995
		 YEAR1996
		 YEAR1997
		 YEAR1998
		 YEAR1999
		 YEAR2000
		 YEAR2001
		 YEAR2002
		 YEAR2003
		 YEAR2004
		 YEAR2005
		 YEAR2006;

   PROC FREQ DATA=TEST;
	TABLES NEW_PHASE1;
   PROC MEANS DATA=TEST;

PROC PRINT DATA=TEST (WHERE=(TOTAL_NEGLECTED LT 0));
VAR WHO_CODE YEAR TOTAL_DEATHS TOTAL_NEGLECTED TOTAL_GLOBAL DEATHS_NO_N_1;
           
   PROC GENMOD DATA=TEST  (WHERE=(_IMPUTATION_ NE .)) NAMELEN=50;
    CLASS WHO_CODE / DESCENDING;
    MODEL NEW_PHASE1 =  &VARLIST / DIST=NB COVB;
    OUTPUT OUT=OUTME XBETA=XB;
    REPEATED SUBJECT = WHO_CODE;
    BY _IMPUTATION_;
    ODS OUTPUT GEEEMPPEST=EST3
	     GEEFITCRITERIA=FIT3
	     NOBS=NUMBEROBS3
	     MODELINFO=INFO3
	     PARMINFO=GMPINFO3
	     COVB=GMCOVB3;

    PROC MIANALYZE PARMS=EST3 COVB=GMCOVB3 PARMINFO=GMPINFO3;
	MODELEFFECTS INTERCEPT &VARLIST;
	TEST_IP_N_4: TEST DEATHS_IP_N_4 = DEATHS_NO_N_4;
	TEST_IP_G_4: TEST DEATHS_IP_G_4 = DEATHS_NO_G_4;
	TEST_GN_IP_4: TEST DEATHS_IP_G_4 = DEATHS_IP_N_4;
	TEST_GN_NO_4: TEST DEATHS_NO_G_4 = DEATHS_NO_N_4;
	TEST_IP_N_3: TEST DEATHS_IP_N_3 = DEATHS_NO_N_3;
	TEST_IP_G_3: TEST DEATHS_IP_G_3 = DEATHS_NO_G_3;
	TEST_GN_IP_3: TEST DEATHS_IP_G_3 = DEATHS_IP_N_3;
	TEST_GN_NO_3: TEST DEATHS_NO_G_3 = DEATHS_NO_N_3;
	TEST_IP_N_2: TEST DEATHS_IP_N_2 = DEATHS_NO_N_2;
	TEST_IP_G_2: TEST DEATHS_IP_G_2 = DEATHS_NO_G_2;
	TEST_GN_IP_2: TEST DEATHS_IP_G_2 = DEATHS_IP_N_2;
	TEST_GN_NO_2: TEST DEATHS_NO_G_2 = DEATHS_NO_N_2;
	TEST_IP_N_1: TEST DEATHS_IP_N_1 = DEATHS_NO_N_1;
	TEST_IP_G_1: TEST DEATHS_IP_G_1 = DEATHS_NO_G_1;
	TEST_GN_IP_1: TEST DEATHS_IP_G_1 = DEATHS_IP_N_1;
	TEST_GN_NO_1: TEST DEATHS_NO_G_1 = DEATHS_NO_N_1;
    ODS OUTPUT PARAMETERESTIMATES=MI_EST3 
	     MODELINFO=MI_INFO3
	     TESTPARAMETERESTIMATES=MI_TESTPARM3;

    PROC MEANS DATA=OUTME NOPRINT;
    VAR XB;
    OUTPUT OUT=AVG_XB MEAN(XB) = XB;

    DATA AVG_XB;
       SET AVG_XB (KEEP=XB);
       MERGEVAL = 1;
    PROC SORT;
       BY MERGEVAL;

    DATA MI_EST3;
       SET MI_EST3;
       MERGEVAL = 1;
    PROC SORT;
       BY MERGEVAL;

    DATA MI_EST3 (DROP=MERGEVAL);
      MERGE MI_EST3 AVG_XB;
      BY MERGEVAL;
      MEM = ESTIMATE*EXP(XB);
    PROC PRINT;

FILENAME RESULTS "&PREFIX._SET4.txt";
%MAKEGENMODTABLE("Robustness check 3: all P1 starts, TRIPS measure, different treatment of HIV",3,4);


